import store from "@/store";

let loadingCount = 0

const startLoading = (options?:Object) => {
  store.dispatch('showloadding', true)
}

const endLoading = () => {
  store.dispatch('showloadding', false)
}

export const showLoading = (options?:Object) => {
  if (loadingCount === 0) {
    startLoading(options)
  }
  loadingCount += 1
}

export const hideLoading = () => {
  if (loadingCount <= 0) {
    return
  }
  loadingCount -= 1
  if (loadingCount === 0) {
    endLoading()
  }
}
